package com.kun.service.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kun.domain.auth.SysUserRole;
import com.kun.service.mapper.auth.SysUserRoleMapper;
import com.kun.service.service.ISysUserRoleService;
import com.kun.service.service.ITAuthRoleService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {

    private final ITAuthRoleService itAuthRoleService;

    public SysUserRoleServiceImpl(ITAuthRoleService itAuthRoleService) {
        this.itAuthRoleService = itAuthRoleService;
    }

    /**
     * 添加用户角色
     */
    @Override
    public boolean addUserRole(Long id, Long value) {
        Assert.isTrue(itAuthRoleService.selectById(value) != null, "角色不存在");
        return save(new SysUserRole(id, value));
    }
}
